<template>
	<div class="personPanel">
		<van-nav-bar safe-area-inset-top>
			<template #left>
				<span class="personTitle">我的</span>
			</template>
		</van-nav-bar>

		<div class="personBox">
			<van-image width="60" height="60" :src="userInfos?.sysUser?.avatar || avatar" />
			<div>
				<p class="name">{{ userInfos?.sysUser?.username }}</p>
				<p class="post">{{ userInfos?.deptName }} - {{ postData.join(',') }}</p>
			</div>
		</div>
		<div class="list">
			<van-cell-group>
				<van-cell icon="edit" style="margin-bottom: 1px" title="我的待办" is-link :value="toDoCount ? toDoCount + '条' : ''" to="/myToDo" />
				<van-cell icon="sign" title="事件单查询" is-link to="/eventSearch" />
			</van-cell-group>
		</div>
	</div>
</template>
<script setup lang="ts">
import { Local } from '/@/utils/storage';
import avatar from '/@/assets/login/avatar.png';
import { getCount } from '/@/api/myTodo/index';
import { getUserInfo } from '/@/api/common';
const userInfos = ref({
	posts: [],
});
const postData = ref([]);
let toDoCount = ref(0);
onMounted(async () => {
	const res: any = await getCount();
	if (res.ok) {
		toDoCount.value = res.data.toDoCount;
	}
	const info = Local.get('userInfos');
	if (!info) {
		getUserInfo(Local.get('token')).then((res: any) => {
			if (res.ok) {
				Local.set('userInfos', res.data);
				userInfos.value = res.data;
			}
		});
	} else {
		userInfos.value = info;
	}
	postData.value = userInfos.value?.posts.map((item: any) => item.postName);
});
</script>
<style lang="scss" scoped>
.personTitle {
	font-size: var(--van-nav-bar-title-font-size);
	font-weight: var(--van-font-bold);
	pointer-events: none;
}

.personBox {
	position: relative;
	display: flex;
	align-items: center;
	padding: 30px 20px;
	background-color: #fff;

	> div {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 20px;

		.name {
			color: #666;
		}

		.post {
			margin-top: 5px;
			color: #999;
		}
	}
}

.personBox::after {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	box-sizing: border-box;
	pointer-events: none;
	content: ' ';
	border-bottom: 1px solid #ccc;
	transform: scaleY(0.5);
}

.list {
	margin-top: 20px;
}
</style>
